import {defineStore} from "pinia";
import http from "../utils/http";
export const useUsers = defineStore("users",{
    state:()=>{
        return{
            usersList:[],
            total:0,
        }
    },
    actions:{
        //模糊搜索 
        async getsearchusers(obj){
            let res = await http.get("/api/user",{params:obj});
            // console.log(res,"user searchs")
            if(res.status === 200){
                //处理后端发送过来的时间  
                // 为多选按钮添加 key值
                let newArr = res.data.data[0].map(v=>{
                    v.createAt = new Date(v.createAt).toLocaleString()
                    v.key = v.id
                    return v
                })
                //赋值总数据
                this.usersList = newArr,
                //赋值总条数
                this.total = res.data.data[1]
            }
        },
        //更改状态
        async setstatususers(obj){
            let res = await http.post("api/user/update",obj);
            //更新成功，重新获取数据
            if(res.status == 201){
                this.getsearchusers({
                    page:1,
                    pageSize:12
                })
            }
        },
    },
    getters:{

    }
})